﻿using K4os.Hash.xxHash;
using MediatR;
using Org.BouncyCastle.Bcpg.OpenPgp;
using SqlSugar;
using StoreIModels;
using StoreISet.Applicationes.Command;
using StoreRepositorys.Interface;
using System.Reflection.Metadata.Ecma335;

namespace StoreISet.Applicationes.CommandHandler
{
    public class StoreFandCommandHandler : IRequestHandler<StoreFandCommand, List<StoreDto>>
    {
        public IStoreRepository _IRepository;
        public IRelationshipStoreRepository _IRelationshipStoreRepository;
        public StoreFandCommandHandler(IStoreRepository storeRepository, IRelationshipStoreRepository relationshipStoreRepository)
        {
            _IRepository = storeRepository;
            _IRelationshipStoreRepository=relationshipStoreRepository;
        }
        public async Task<List<StoreDto>> Handle(StoreFandCommand request, CancellationToken cancellationToken)
        {
            var list = await _IRelationshipStoreRepository.GetAllasync();
            var res = from x in await _IRepository.GetAllasync()
                      where (x.StoreId == request.id)
                      select new StoreDto
                      {
                          StoreId = x.StoreId,
                          StoreName = x.StoreName,
                          BranchStoreName = x.BranchStoreName,
                          AddressProvince = x.AddressProvince,
                          AddressCity = x.AddressCity,
                          AddressCounty = x.AddressCounty,
                          AddressMerchantDetailed = x.AddressMerchantDetailed,
                          StoreImge = x.StoreImge,
                          CustomerPhone = x.CustomerPhone,
                          StoreState = x.StoreState,
                          Storeintroduce = x.Storeintroduce,
                          StoreNotice = x.StoreNotice,
                          StoreTraffic = x.StoreTraffic,
                          adderIdSe = (from b in list
                                       where (b.StoreId == request.id)
                                       select new RelationshipStoreModels
                                       {
                                           AssortedId = b.StoreId,
                                       }).ToString()
                      };
            return res.ToList();
           }


               
        }
    }

